//
//  SelectPicCollectionViewCell.m
//  TheDragon
//
//  Created by appleLJ on 2017/6/29.
//  Copyright © 2017年 LJ. All rights reserved.
//

#import "SelectPicCollectionViewCell.h"

@implementation SelectPicCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _imgView = [[UIImageView alloc] init];
        _imgView.image = [UIImage imageNamed:@"weixin"];
        _imgView.contentMode = UIViewContentModeScaleAspectFill;
        _imgView.clipsToBounds = YES;
        [self.contentView addSubview:_imgView];
        
        _deleteImgView = [[UIImageView alloc] init];
        _deleteImgView.image = [UIImage imageNamed:@"guanbi"];
        _deleteImgView.hidden = YES;
        _deleteImgView.userInteractionEnabled = YES;
        //手势事件
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteEvent)];
        [_deleteImgView addGestureRecognizer:tapGesture];
        [self.contentView addSubview:_deleteImgView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = self.bounds;
    _deleteImgView.frame = CGRectMake(self.frame.size.width-22, 8, 20, 20);
}

#pragma mark -- Event

- (void)deleteEvent{
    NSLog(@"删除");
    if (self.deleteHandle) {
        self.deleteHandle();
    }
}

#pragma mark -- set

- (void)setImg:(UIImage *)img{
    _img = img;
    if (img) {
        _imgView.image = img;
        _deleteImgView.hidden = NO;
    }else{
        _imgView.image = [UIImage imageNamed:@"fankui"];
        _deleteImgView.hidden = YES;
    }
}

@end
